package com.jyw.business.obstacles.controller;

import com.jyw.business.obstacles.domain.ObsOrderEvaluate;
import com.jyw.business.obstacles.service.IObsOrderEvaluateService;
import com.jyw.common.annotation.Log;
import com.jyw.common.core.controller.BaseController;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.core.page.TableDataInfo;
import com.jyw.common.enums.BusinessType;
import com.jyw.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 工单评价Controller
 *
 * @author ZhangCheng
 * @date 2023-08-10
 */
@Api(tags = "工单评价Api")
@RestController
@RequestMapping("/obstacles/evaluate")
public class ObsOrderEvaluateController extends BaseController {

    @Autowired
    private IObsOrderEvaluateService obsOrderEvaluateService;

    /**
     * 查询工单评价列表
     */
    @PreAuthorize("@ss.hasPermi('obstacles:evaluate:list')")
    @GetMapping("/list")
    @ApiOperation("查询工单评价列表")
    public TableDataInfo<ObsOrderEvaluate> list(ObsOrderEvaluate obsOrderEvaluate) {
        startPage();
        List<ObsOrderEvaluate> list = obsOrderEvaluateService.selectObsOrderEvaluateList(obsOrderEvaluate);
        return getDataTable(list);
    }

    /**
     * 导出工单评价列表
     */
    @PreAuthorize("@ss.hasPermi('obstacles:evaluate:export')")
    @Log(title = "工单评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出工单评价列表")
    public void export(HttpServletResponse response, ObsOrderEvaluate obsOrderEvaluate) {
        List<ObsOrderEvaluate> list = obsOrderEvaluateService.selectObsOrderEvaluateList(obsOrderEvaluate);
        ExcelUtil<ObsOrderEvaluate> util = new ExcelUtil<ObsOrderEvaluate>(ObsOrderEvaluate.class);
        util.exportExcel(response, list, "工单评价数据");
    }

    /**
     * 获取工单评价详细信息
     */
    @PreAuthorize("@ss.hasPermi('obstacles:evaluate:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取工单评价详细信息")
    public CommonResult<ObsOrderEvaluate> getInfo(@PathVariable("id") Long id) {
        return CommonResult.success(obsOrderEvaluateService.selectObsOrderEvaluateById(id));
    }

    /**
     * 新增工单评价
     */
    @PreAuthorize("@ss.hasPermi('obstacles:evaluate:add')")
    @Log(title = "工单评价", businessType = BusinessType.INSERT)
    @PostMapping("/save")
    @ApiOperation("新增工单评价")
    public CommonResult add(@RequestBody ObsOrderEvaluate obsOrderEvaluate) {
        return CommonResult.success(obsOrderEvaluateService.insertObsOrderEvaluate(obsOrderEvaluate));
    }

    /**
     * 修改工单评价
     */
    @PreAuthorize("@ss.hasPermi('obstacles:evaluate:edit')")
    @Log(title = "工单评价", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    @ApiOperation("修改工单评价")
    public CommonResult edit(@RequestBody ObsOrderEvaluate obsOrderEvaluate) {
        return CommonResult.success(obsOrderEvaluateService.updateObsOrderEvaluate(obsOrderEvaluate));
    }

    /**
     * 删除工单评价
     */
    @PreAuthorize("@ss.hasPermi('obstacles:evaluate:remove')")
    @Log(title = "工单评价", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除工单评价")
    public CommonResult remove(@PathVariable Long[] ids) {
        return CommonResult.success(obsOrderEvaluateService.deleteObsOrderEvaluateByIds(ids));
    }
}
